<template>
    <p-card>
        <p-page-header style="border: 1px solid rgb(235, 237, 240)" title="MQE复核操作">
            <template slot="extra">
                <!--<p-button key="1" type="primary" @click="saveDataBtn">保存</p-button>

                <p-popconfirm
                        title="确定要提交吗？"
                        ok-text="确定"
                        cancel-text="取消"
                        @confirm="submitData"
                        @cancel="cancel"
                >
                  <p-button type="primary">提交</p-button>
                </p-popconfirm>-->

               <!-- <p-button @click="backToIndex">取消</p-button>-->

                <!-- <p-button key="1" type="primary"  @click="submitData">
                   提交
                </p-button>-->
            </template>
        </p-page-header>

        <h4 class="title">基础信息</h4>
        <p-form-model
                ref="baseInfoData"
                :model="baseInfoData"
                :rules="rules"
                :label-col="labelCol"
                :wrapper-col="wrapperCol"
        >
            <p-row :gutter="24">
                <p-col :span="8">
                    <p-form-model-item ref="inspectBillno" label="送检单号" prop="inspectBillno">
                        <p-input
                                readOnly
                                v-model="baseInfoData.inspectBillno"
                                @blur="
          () => {
            $refs.inspectBillno.onFieldBlur();
          }
        "
                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="sendBillno" label="送货单号" prop="sendBillno">
                        <p-input
                                readOnly
                                v-model="baseInfoData.sendBillno"
                                @blur="
          () => {
            $refs.sendBillno.onFieldBlur();
          }
        "
                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="mcode" label="物料编号" prop="mcode">
                        <p-input
                                readOnly
                                v-model="baseInfoData.mcode"
                                @blur="
          () => {
            $refs.mcode.onFieldBlur();
          }
        "
                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="mname" label="物料名称" prop="mname">
                        <p-input
                                readOnly
                                v-model="baseInfoData.mname"
                                @blur="
          () => {
            $refs.mname.onFieldBlur();
          }
        "
                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="productOneType" label="物料一级分类" prop="productOneType">
                        <p-input
                                readOnly
                                v-model="baseInfoData.productOneType"

                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="productTwoType" label="物料二级分类" prop="productTwoType">
                        <p-input
                                readOnly
                                v-model="baseInfoData.productTwoType"

                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="productThreeType" label="物料三级分类" prop="productThreeType">
                        <p-input
                                readOnly
                                v-model="baseInfoData.productThreeType"
                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="sampingMethod" label="抽检方式" prop="sampingMethod">
                        <p-input
                                v-if="baseInfoData.sampingMethod==1"
                                readOnly
                                style="color:red"
                                v-model="baseInfoData.sampingMethodText"

                        />
                        <p-input
                                v-else
                                readOnly
                                style="color:red"
                                v-model="baseInfoData.aqlSimpleStandardName"

                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="simpleQty" label="抽检数量" prop="simpleQty">
                        <p-input
                                readOnly
                                v-model="baseInfoData.simpleQty"
                                @blur="
          () => {
            $refs.simpleQty.onFieldBlur();
          }
        "
                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="matSn" label="物料管控方式" prop="matSn">
                        <p-input
                                readOnly
                                v-model="baseInfoData.matSnText"
                                @blur="
          () => {
            $refs.matSn.onFieldBlur();
          }
        "
                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="custno" label="供应商编码" prop="custno">
                        <p-input
                                readOnly
                                v-model="baseInfoData.custno"
                                @blur="
          () => {
            $refs.custno.onFieldBlur();
          }
        "
                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="custname" label="供应商名称" prop="custname">
                        <p-input
                                readOnly
                                v-model="baseInfoData.custname"
                                @blur="
          () => {
            $refs.custname.onFieldBlur();
          }
        "
                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="sendInspectBy" label="送检人" prop="sendInspectBy">
                        <p-input
                                readOnly
                                v-model="baseInfoData.sendInspectBy"
                                @blur="
          () => {
            $refs.sendInspectBy.onFieldBlur();
          }
        "
                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="sendInspectTime" label="送检时间" prop="sendInspectTime">
                        <p-input
                                readOnly
                                v-model="baseInfoData.sendInspectTime"
                                @blur="
          () => {
            $refs.sendInspectTime.onFieldBlur();
          }
        "
                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="unqualifiedQty" label="不合格数量" prop="unqualified_qty">
                        <p-input
                                readOnly
                                v-model="baseInfoData.unqualifiedQty"
                                @blur="
          () => {
            $refs.unqualified_qty.onFieldBlur();
          }
        "
                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="checkBy" label="检验人" prop="checkBy">
                        <p-input
                                readOnly
                                v-model="baseInfoData.checkBy"
                                @blur="
          () => {
            $refs.checkBy.onFieldBlur();
          }
        "
                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="inMethod" label="来料方式" prop="inMethod">
                        <p-select
                                v-model="baseInfoData.inMethod"
                                @blur="() => {$refs.inMethod.onFieldBlur();}"
                                disabled
                        >
                            <p-select-option :value="1">
                                进料检验
                            </p-select-option>
                            <p-select-option :value="2">
                                直发协同
                            </p-select-option>
                        </p-select>



                    </p-form-model-item>
                </p-col>
                <p-col :span="8">
                    <p-form-model-item ref="currentAddress" label="当前地址" prop="currentAddress">
                        <p-input
                                readOnly
                                v-model="baseInfoData.currentAddress"
                                @blur="
          () => {
            $refs.currentAddress.onFieldBlur();
          }
        "
                        />
                    </p-form-model-item>
                </p-col>

                <!-- <p-col :span="24">
                  <p-form-model-item :wrapper-col="{offset: 2 }">
                    <p-button type="primary" @click="onSubmit">Create</p-button>
                    <p-button style="margin-left: 10px;" @click="resetForm">Reset</p-button>
                  </p-form-model-item>
                </p-col>-->
            </p-row>

            <p-row>
                <p-col :span="5">
                    <p-tag>检验报告详情*</p-tag><a>查询</a>
                </p-col>
                <p-col :span="5">
                    <p-tag>供应商报告*</p-tag><a>查询</a>
                </p-col>
                <p-col :span="5">
                    <p-tag>物料SN详情*</p-tag><a @click="openPdSnDetailModal">查询</a>
                </p-col>
                <p-col :span="5">
                    <p-tag>封样图片*</p-tag><a>查询</a>
                </p-col>
                <p-col :span="4">
                    <p-tag>检验结论*</p-tag>
                    <p-span v-if="baseInfoData.inspectResult==1" style="color:blue">合格</p-span>
                    <p-span v-else-if="baseInfoData.inspectResult==2" style="color:red">不合格</p-span>
                </p-col>


            </p-row>

        </p-form-model>

        <h4 class="title">不合格内容</h4>
        <p-table
                :columns="modal2InspectionColumns"
                :data-source="baseInfoData.failList"
                class="components-table-demo-nested"
                bordered
                style="margin-top:10px;"
        ></p-table>

        <h4 class="title">审批记录</h4>
        <p-table
                :columns="approvalRecordColumns"
                :data-source="baseInfoData.approveRecordList"
                class="components-table-demo-nested"
                bordered
                style="margin-top:10px;"
        ></p-table>

        <h4 class="title">审批处理</h4>
        <p-form-model
                ref="processProcessingData"
                :label-col="{span:2}"
                :wrapper-col="{span:12}"
                :model="baseInfoData"
                style="margin-top:12px;"
        >
            <p-row :gutter="24">
                <p-col :span="24">
                    <p-form-model-item ref="operation" label="操作" prop="operation">
                        <p-radio-group v-model="baseInfoData.operation">
                            <p-radio :value="1">通过</p-radio>
                            <p-radio :value="2">驳回</p-radio>
                        </p-radio-group>
                    </p-form-model-item>
                </p-col>
                <p-col :span="24">
                    <p-form-model-item ref="remark" label="备注" prop="remark">
                        <p-input
                                v-model="baseInfoData.remark"
                                type="textarea"
                                @blur="
          () => {
            $refs.remark.onFieldBlur();
          }
        "
                        />
                    </p-form-model-item>
                </p-col>
                <p-col :span="24">
                    <p-form-model-item ref="currentHandler" label="当前处理人" prop="currentHandler">
                        <p-input
                                readOnly
                                type="input"
                                v-model="baseInfoData.currentHandler"
                                @blur="
          () => {
            $refs.currentHandler.onFieldBlur();
          }
        "
                        />
                    </p-form-model-item>
                </p-col>
            </p-row>
        </p-form-model>
        <p-popconfirm
                title="确定要提交吗？"
                ok-text="确定"
                cancel-text="取消"
                @confirm="submitData"
                @cancel="cancel"
        >
            <p-button type="primary">提交</p-button>
        </p-popconfirm>



        <p-modal v-model="pdSnDetailModalVisible" title="物料SN详情" :footer="null" :width="1200">
            <p-table
                    :data-source="baseInfoData.matSnDetail"
                    :columns="pdSnDetailColumns"
            >
            </p-table>
        </p-modal>
    </p-card>
</template>

<script>
    // import { JeecgListMixin } from "@/mixins/JeecgListMixin";
    import { api } from "@/api/manage";
    import JSuperQuery from "@/components/jeecg/JSuperQuery.vue";
    import { filterObj } from "@/utils/util";
    import Vue from "vue";
    import {getAction, putAction} from "../../../api/manage";
    import dayjs from "dayjs";

    export default {
        name: "MesQcMQEdbCheckApproval",
        // mixins: [JeecgListMixin],
        props:['mqVisible','mqLoad','mqData'],
        data() {
            return {
                labelCol: { span: 8 },
                wrapperCol: { span: 14 },
                rules: {
                    inspectBillno: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    sendBillno: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    sendBillnoLine: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    mcode: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    mname: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    mbig: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    msmall: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    sampingMethod: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    simpleQty: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    matSn: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    custno: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    custname: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    sendInspectBy: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    sendInspectTime: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    sendInspectQty: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    checkBy: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    inMethod: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    custReport: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    tcsp: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    mSnDetail: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    photoUrl: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    inspectResult: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    currentAddress: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    unqualifiedQty: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    checkReportDetails: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                    custCheckReport: [
                        {
                            required: true,
                            message: "Please input Activity name",
                            trigger: "blur",
                        },
                    ],
                },

                modal2Visible: false,
                sampingMethodList:[],
                pdSnDetailModalVisible:false,
                sampingMethodMap:[],
                matSnList:[],
                matSnMap:[],
                pdSnDetailColumns:[
                    { title: "物料编码", dataIndex: "mcode", key: "mcode" },
                    { title: "物料名称", dataIndex: "mname", key: "mname" },
                    { title: "物料一级分类", dataIndex: "productOneType", key: "productOneType" },
                    { title: "物料二级分类", dataIndex: "productTwoType", key: "productTwoType" },
                    { title: "物料三级分类", dataIndex: "productThreeType", key: "productThreeType" },
                    { title: "SN", dataIndex: "sn", key: "sn" },
                ],
                baseInfoData: {
                    //基础信息
                    inspectBillno: "001", //送检单号
                    sendBillno: "", //送货单号
                    sendBillnoLine: "001", //送货单行号
                    mcode: "", //物料编号
                    mname: "", //物料名称
                    mbig: "", //物料大类名称
                    msmall: "", //物料小类名称
                    sampingMethod: "", //抽检方式
                    simpleQty: "3", //抽检数量
                    matSn: "2020-01-01", //物料管理方式
                    custno: "", //供应商编码
                    custname: "", //供应商名称
                    sendInspectBy: "", //送检人
                    sendInspectTime: 1, //送检时间
                    sendInspectQty: 3, //送检数量
                    checkBy: "fdafsdd", //检验人
                    inMethod: "", //来料方式
                    custReport: "", //供应商报告
                    tcsp: "", //技术规格书
                    mSnDetail: "", //物料SN详情
                    photoUrl: "", //封样图片
                    inspectResult: "", //检验结论
                    operation: 1, //操作
                    inspectMethod: 1, //检验方式
                    remark: "", //备注
                    currentHandler:"",//当前处理人
                    fileUrl: "", //附件
                    currentAddress: "", //当前地址
                    unqualifiedQty: "", //不合格数量
                    checkReportDetails: "", //检验报告详情
                    custCheckReport: "", //供应商检验报告
                },
                modal2InspectionColumns: [
                    {
                        title: "序号",
                        dataIndex: "",
                        key: "rowIndex",
                        width: 10,
                        align: "center",
                        customRender: function (t, r, index) {
                            return parseInt(index) + 1;
                        },
                    },
                    {
                        title: "检验项目",
                        dataIndex: "inspectProject",
                        key: "inspectProject",
                    },
                    { title: "缺陷等级", dataIndex: "flawLevel", key: "flawLevel" },
                    { title: "检验要点", dataIndex: "inspectPoint", key: "inspectPoint" },
                    { title: "物料SN/PN", dataIndex: "matSnPn", key: "matSnPn" },
                    { title: "标准值", dataIndex: "standardValue", key: "standardValue" },
                    { title: "上限值", dataIndex: "upperValue", key: "upperValue" },
                    { title: "下限值", dataIndex: "downValue", key: "downValue" },
                    { title: "参数", dataIndex: "param", key: "param" },
                    { title: "实测值", dataIndex: "actualValue", key: "actualValue" },
                    { title: "检验结论", dataIndex: "inspectResult", key: "inspectResult" },
                    {
                        title: "检验完成时间",
                        dataIndex: "inspectFinishTime",
                        key: "inspectFinishTime",
                    },
                ],
                modal2InspectionData: [
                    {
                        key: 1,
                        inspectProject: "物料齐套",
                        flawLevel: "B",
                        inspectPoint: "装箱单与包装SOP一致",
                        matSnPn: "",
                        standardValue: "",
                        upperValue: "",
                        downValue: "",
                        param: "",
                        actualValue: "",
                        inspectResult: "NG",
                        inspectFinishTime: "2020-03-11 10:27",
                    },
                    {
                        key: 2,
                        inspectProject: "物料齐套",
                        flawLevel: "B",
                        inspectPoint: "装箱单与包装SOP一致",
                        matSnPn: "",
                        standardValue: "",
                        upperValue: "",
                        downValue: "",
                        param: "",
                        actualValue: "",
                        inspectResult: "NG",
                        inspectFinishTime: "2020-03-11 10:27",
                    },
                ],
                //审批记录
                approvalRecordColumns: [
                    {
                        title: "序号",
                        dataIndex: "",
                        key: "rowIndex",
                        width: 10,
                        align: "center",
                        customRender: function (t, r, index) {
                            return parseInt(index) + 1;
                        },
                    },
                    {
                        title: "时间",
                        dataIndex: "createTime",
                        key: "createTime",
                        customRender:(text) =>{
                            if(!text){
                                return "";
                            }else{
                                return this.dayjs(text).format('YYYY-MM-DD HH:mm:ss')
                            }
                        }

                    },
                    { title: "操作人员", dataIndex: "opeBy", key: "opeBy" },
                    { title: "状态", dataIndex: "opeContent", key: "opeContent" },
                    { title: "备注", dataIndex: "remark", key: "remark" },
                ],
                approvalRecordData: [
                    {
                        key: 1,
                        createTime: "20200316",
                        opeBy: "吴丹",
                        opeContent: "提交文档到MQE复核",
                        remark: "来料物料与SOP要求不符合",
                    },
                    {
                        key: 2,
                        createTime: "20200316",
                        opeBy: "吴丹",
                        opeContent: "提交文档到MQE复核",
                        remark: "来料物料与SOP要求不符合",
                    },
                ],
            };
        },
        computed: {

        },


        created() {
            this.initSampingMethodList();
            this.initMatSnList();
            this.mqListener();},

        methods: {
            mqListener(){
                console.log(this.mqVisible)
                console.log(this.mqLoad)
                console.log(this.mqData)
                this.initData(this.mqData);
            },
            dayjs,
            backToIndex(){
                let mqData = this.mqData;
                this.$emit('update:mqVisible', 1);
                this.$emit('update:mqLoad', false);
                mqData.id = 0;
                mqData.inMethod = "";
                this.$emit('update:mqData', mqData);
            },
            /**
             * 初始化加载数据
             */
            initData(query){
                getAction('/mes-quality/mesQcIncomeBasicInfo/selectByProcessId/'+this.$route.query.processInstanceId).then(res=>{
                    if(res.success){
                       /* let data = res.data;
                        let key = 1;
                        data.forEach(item=>{
                            item.key =key;
                            key = key+1;
                        })
                        this.recordData = data;*/
                        if(res.code!=0){
                            this.$message.warning(res.msg)
                        }
                        let data = res.data;
                        data.unqualifiedQty = data.failList.length;
                        data.matSnText = data.matSn?this.matSnMap[data.matSn]?this.matSnMap[data.matSn].title:'':'';
                        data.sampingMethodText = data.sampingMethod?this.sampingMethodMap[data.sampingMethod]?this.sampingMethodMap[data.sampingMethod].title:'':'';
                        this.baseInfoData = data;
                    }else{
                        this.$message.warning(res.msg);
                    }
                })
                /*if(!query.id){
                    this.$message.warning("请通过复核任务清单选择单号进入！");

                }else{
                    let id = query.id;

                    getAction('/mes-quality/mesQcIncomeBasicInfo/query/all/info/by/id/'+id).then(res=>{
                        if (res.success) {
                            if(res.code!=0){
                                this.$message.warning(res.msg)
                            }
                            let data = res.data;
                            data.unqualifiedQty = data.failList.length;
                            data.matSnText = data.matSn?this.matSnMap[data.matSn]?this.matSnMap[data.matSn].title:'':'';
                            data.sampingMethodText = data.sampingMethod?this.sampingMethodMap[data.sampingMethod]?this.sampingMethodMap[data.sampingMethod].title:'':'';
                            this.baseInfoData = data;

                        } else {
                            this.$message.warning(res.msg);
                        }
                    })

                }*/
            },

            openPdSnDetailModal(){
                this.pdSnDetailModalVisible = true;
            },
//封装listToMap
            listToMap(list,name){
                let map = {};
                for(let i in list){
                    map[list[i][name]] = list[i];
                }
                return map;
            },
            initSampingMethodList(){
                getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'rc_inspect_method'}).then(res=>{
                    if(res.success){
                        this.sampingMethodList = res.data;
                        this.sampingMethodMap = this.listToMap(this.sampingMethodList,'value');
                    }
                })
            },

            initMatSnList(){
                getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'ba_cpinfo_control'}).then(res=>{
                    if(res.success){
                        this.matSnList = res.data;
                        this.matSnMap = this.listToMap(this.matSnList,'value');
                    }
                })
            },

            submitData(){
                let data = this.baseInfoData;
                let flag = true;
                if(!data.operation||data.operation===""){

                    flag = false;
                    this.$message.error("请选择 通过/驳回 ！");
                }
                if(data.inspectMethod===""){
                    flag = false;
                    this.$message.error("请选择检验方式 ！");
                }
                if(data.operation==2&&(!data.remark||data.remark=='')){
                    flag = false;
                    this.$message.error("驳回后必填驳回的原因 ！");
                }

                if(flag){
                    putAction('/mes-quality/mesQcIncomeBasicInfo/submit/entity',data).then(res=>{
                        if(res.success){
                            this.$message.success("操作成功");
                            this.backToIndex();
                        }else{
                            this.$message.warning(res.msg);
                        }
                    })
                }



            }
        },
    };
</script>
<style scoped>
    @import "~@assets/less/common.less";
    .title {
        padding: 8px 12px;
        background: #fafafa;
    }
    .title:not(:first-child) {
        margin-top: 25px;
    }
    /deep/ .poros-form {
        margin-top: 15px;
    }
    /deep/ .poros-table-body {
        overflow-x: auto !important;
    }
    /deep/ .poros-col {
        min-height: 54px;
    }
    /deep/ .poros-table thead th {
        height: 44px;
    }
</style>
